package com.dwxt.cdms.controller;

import com.dwxt.cdms.base.Page;
import com.dwxt.cdms.constant.EquipCategory;
import com.dwxt.cdms.service.PoctService;
import com.dwxt.common.base.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author yanlong
 * @version 1.0
 * @className PoctController
 * @date 2021/5/9 9:48
 */
@RequestMapping("/cdms/poct")
@RestController
public class PoctController {

    @Autowired
    private PoctService poctService;

    /**
     * 接收poct数据
     * @param request
     * @return
     */
    @RequestMapping("/receiveData")
    public BaseResult receiveData(HttpServletRequest request) {
        return poctService.receiveData(request);
    }

    /**
     * 按用户分组查询最新数据并分页
     * @param page
     * @param name
     * @param type
     * @return
     */
    @RequestMapping("/pageGroup")
    public BaseResult pageGroup(Page page,String name,String type,String category){
        //Assert.isTrue(EquipCategory.POCT4.equals(category) || EquipCategory.POCT8.equals(category), "设备类型错误");
        return poctService.pageGroup(page,name,type,category);
    }

    /**
     * 数据详情分页
     * @param page
     * @param customerId
     * @param type
     * @return
     */
    @RequestMapping("/page")
    public BaseResult page(Page page,Integer customerId,String type,String category,Integer partId){
        Assert.isTrue(!EquipCategory.POCT4.equals(category) || !EquipCategory.POCT7.equals(category), "设备类型错误");
        return poctService.page(page,customerId,type,category,partId);
    }


    /**
     * 归属角色Poct数据
     * @param map
     * @return
     */
    @PostMapping("/updatePart")
    public BaseResult updatePart(@RequestBody Map map){
        return poctService.updatePart(map);
    }


    /**
     * 电视端数据详情
     * @param scope 时间范围
     * @param customerId
     * @param type
     * @return
     */
    @RequestMapping("/dataList")
    public BaseResult dataList(@RequestParam(required = true) String type,
                                @RequestParam(required = true) Integer customerId,
                               @RequestParam(required = true,defaultValue = "1")Integer scope,
                               @RequestParam(required = true,defaultValue = "0")Integer partId){
        return poctService.dataList(customerId,type,partId,scope);
    }
}
